import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class NettyEchoHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf byteBuf = (ByteBuf) msg;

        int len = byteBuf.readableBytes();
        byte[] buff = new byte[len];
        byteBuf.getBytes(0, buff);
        System.out.println("收到消息：" + new String(buff));
        ChannelFuture channelFuture = ctx.writeAndFlush(msg);
        super.channelRead(ctx, msg);
    }
}
